package com.turnengine.client.global.translation.command;

import com.javabi.common.locale.LanguageCountry;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Get Translation By Text.
 */
public class GetTranslationByText implements IGetTranslationByText {

	/** The command id. */
	public static final short COMMAND_ID = 404;

	/** The english. */
	private String english;
	/** The language. */
	private LanguageCountry language;

	/**
	 * Creates a new Get Translation By Text.
	 */
	public GetTranslationByText() {
	}

	/**
	 * Creates a new Get Translation By Text.
	 * @param english the english
	 * @param language the language
	 */
	public GetTranslationByText(String english, LanguageCountry language) {
		setEnglish(english);
		setLanguage(language);
	}

	/**
	 * Creates a new Get Translation By Text.
	 * @param iGetTranslationByText the i get translation by text
	 */
	public GetTranslationByText(IGetTranslationByText iGetTranslationByText) {
		setEnglish(iGetTranslationByText.getEnglish());
		setLanguage(iGetTranslationByText.getLanguage());
	}

	/**
	 * Returns the english.
	 * @return the english.
	 */
	public String getEnglish() {
		return english;
	}

	/**
	 * Returns the language.
	 * @return the language.
	 */
	public LanguageCountry getLanguage() {
		return language;
	}

	/**
	 * Sets the english.
	 * @param english the english to set.
	 */
	public void setEnglish(String english) {
		if (english == null) {
			throw new NullPointerException("english");
		}
		this.english = english;
	}

	/**
	 * Sets the language.
	 * @param language the language to set.
	 */
	public void setLanguage(LanguageCountry language) {
		if (language == null) {
			throw new NullPointerException("language");
		}
		this.language = language;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(211, 37);
		hash.append(english);
		hash.append(language);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GetTranslationByText) {
			GetTranslationByText compare = (GetTranslationByText) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.english, compare.english);
			equals.append(this.language, compare.language);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGetTranslationByText compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.english, compare.getEnglish());
		builder.append(this.language, compare.getLanguage());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		if (english != null) {
			string.append("english", english);
		}
		if (language != null) {
			string.append("language", language);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
